//
//  PTStuLifeServiceMyReleaseViewController.m
//  PlanTech
//  生活服务-我的发布页
//  Created by ruifeng song on 2018/7/10.
//  Copyright © 2018年  androidlongs. All rights reserved.
//

#import "PTStuLifeServiceMyReleaseViewController.h"
#import "PTStuLifeServiceHeaderView.h"
#import "PTStuLifeServiceMyReleaseCell.h"
#import "PTStuLSReleaseDetailViewController.h"
#import "PTCoreManager+LifeService.h"
#import "PTCoreObject+LifeService.h"
#import "PTStuLifeServiceReleaseViewController.h"
#import "PTRateView.h"

@interface PTStuLifeServiceMyReleaseViewController ()<UITableViewDelegate,UITableViewDataSource,MyReleaseCellDelegate,UIScrollViewDelegate,PTRateViewDelegate,LifeServiceHeaderViewDelegate,UIAlertViewDelegate>
{
    NSInteger currentPage;
    
    int allReleasePageNum;
    int waitTakeOrderPageNum;
    int alreadyTakeOrderPageNum;
    int waitFinishPageNum;
    int waitCommentPageNum;
}
@property(nonatomic,copy)NSString * serviceUUID;   //操作订单需要
@property(nonatomic,strong)UITableViewCell * currentReleaseCell;

@property(nonatomic,assign)int currentPageNum;
@property(nonatomic,assign)BOOL isRefreshData;
@property(nonatomic,strong)UILabel *bottomLabel;
@property(nonatomic,assign)NSInteger status;
@property(nonatomic,strong)UIScrollView *myReleaseJobScrolView;
@property (nonatomic,strong)PTStuLifeServiceHeaderView *headerView;

@property (nonatomic,strong)UITableView *allReleaseTableView;
@property (nonatomic,strong)UITableView *waitTakeOrderTableView;
@property (nonatomic,strong)UITableView *alreadyTakeOrderTableView;
@property (nonatomic,strong)UITableView *waitDoneTableView;
@property (nonatomic,strong)UITableView *waitCommentTableView;

//全部
@property(nonatomic,strong)NSMutableArray<LifeServiceMyListModel *> *allReleaseArray;

//待接单
@property(nonatomic,strong)NSMutableArray<LifeServiceMyListModel *> *waitTakeOrderArray;

//已接单
@property(nonatomic,strong)NSMutableArray<LifeServiceMyListModel *> *alreadyTakeOrderArray;

//待完成
@property(nonatomic,strong)NSMutableArray<LifeServiceMyListModel *> *waitDoneArray;

//待评价
@property(nonatomic,strong)NSMutableArray<LifeServiceMyListModel *> *waitCommentArray;

@end

@implementation PTStuLifeServiceMyReleaseViewController

-(void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}

-(NSMutableArray *)allReleaseArray
{
    if (_allReleaseArray ==nil) {
        
        _allReleaseArray = [NSMutableArray array];
    }
    return _allReleaseArray;
}

-(NSMutableArray *)waitTakeOrderArray
{
    if (_waitTakeOrderArray ==nil) {
        
        _waitTakeOrderArray =[NSMutableArray array];
    }
    return _waitTakeOrderArray;
}

-(NSMutableArray *)alreadyTakeOrderArray
{
    if (_alreadyTakeOrderArray == nil) {
        
        _alreadyTakeOrderArray = [NSMutableArray array];
    }
    return _alreadyTakeOrderArray;
}

-(NSMutableArray *)waitDoneArray
{
    if (_waitDoneArray == nil) {
        
        _waitDoneArray = [NSMutableArray array];
    }
    return _waitDoneArray;
}

-(NSMutableArray *)waitCommentArray
{
    if (_waitCommentArray == nil) {
        
        _waitCommentArray = [NSMutableArray array];
    }
    return _waitCommentArray;
}

//在页面出现的时候就将黑线隐藏起来

-(void)viewWillAppear:(BOOL)animated
{
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
}

//在页面消失的时候就让navigationbar还原样式

-(void)viewWillDisappear:(BOOL)animated{
    
    [self.navigationController.navigationBar setShadowImage:nil];
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"我的发布";
    
    self.view.backgroundColor = BaseViewBackgroundColor;
    
    currentPage = 0;
    
    self.status = PTLifeService_AllStatus;
    
    self.isRefreshData = NO;
    self.currentPageNum = [self getCurrentRequestPageWithRefresh:YES];
    
    [self createView];
    
    [self requestData];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(requestData) name:kPT_Global_Notification_RefreshMyReleaseList object:nil];
}

-(int)getCurrentRequestPageWithRefresh:(BOOL)isHeaderRefreshing
{
    if (self.status == PTLifeService_AllStatus) {
        if (isHeaderRefreshing) {
            allReleasePageNum = 1;
        }
        else
        {
            allReleasePageNum++;
        }
        return allReleasePageNum;
    }
    else if (self.status == PTLifeService_NormalStatus)
    {
        if (isHeaderRefreshing) {
            waitTakeOrderPageNum = 1;
        }
        else
        {
            waitTakeOrderPageNum ++;
        }
        return waitTakeOrderPageNum;
    }
    else if (self.status == PTLifeService_TakeOrderUnDoneStatus)
    {
        if (isHeaderRefreshing) {
            alreadyTakeOrderPageNum = 1;
        }
        else
        {
            alreadyTakeOrderPageNum ++;
        }
        return alreadyTakeOrderPageNum;
    }
    else if (self.status == PTLifeService_TakeOrderDoneStatus)
    {
        if (isHeaderRefreshing) {
            waitFinishPageNum = 1;
        }
        else
        {
            waitFinishPageNum ++;
        }
        return waitFinishPageNum;
    }
    else if (self.status == PTLifeService_FinishStatus)
    {
        if (isHeaderRefreshing) {
            waitCommentPageNum = 1;
        }
        else
        {
            waitCommentPageNum ++;
        }
        return waitCommentPageNum;
    }
    return 1;
}

-(void)requestData
{
    [self requestMyReleaseListDataWithStatus:self.status pageNum:self.currentPageNum];
}

//获取我的发布数据
-(void)requestMyReleaseListDataWithStatus:(PTLifeServiceStatus)status pageNum:(NSInteger)pageNum
{
    SINAUserModel *userModel = [[SINACommonUserHelper share]getUserModel];
    
    WeakSelf;
    [[PTCoreManager shareInstance]performGetMyReleaseServiceListWithUserUUID:userModel.userUid page:pageNum num:10 status:status Completion:^(id _Nullable retObject, NSError * _Nullable retError) {
        
        if (retObject) {
            
            if ([retObject isKindOfClass:[PTMJsonResult class]]) {
                
            }
            else
            {
                [weakSelf ChangeResponseDataWithArray:retObject];
            }
        }
        else
        {
            
        }
        
    }];
}

-(void)ChangeResponseDataWithArray:(NSArray * )obj
{
    switch (self.status) {
        case PTLifeService_AllStatus:
        {
            if (self.currentPageNum ==1) {
                [self.allReleaseArray removeAllObjects];
                [self.allReleaseTableView.mj_header endRefreshing];
                [self.allReleaseTableView.mj_footer resetNoMoreData];
            }
            else
            {
                [self.allReleaseTableView.mj_footer endRefreshing];
            }
            [self.allReleaseArray addObjectsFromArray:obj];
            [self.allReleaseTableView reloadData];
            
            if (obj.count < 10) {
                [self.allReleaseTableView.mj_footer endRefreshingWithNoMoreData];
            }
        }
            break;
        case PTLifeService_NormalStatus:
        {
            if (self.currentPageNum ==1) {
                [self.waitTakeOrderArray removeAllObjects];
                [self.waitTakeOrderTableView.mj_header endRefreshing];
                [self.waitTakeOrderTableView.mj_footer resetNoMoreData];
            }
            else
            {
                [self.waitTakeOrderTableView.mj_footer endRefreshing];
            }
            [self.waitTakeOrderArray addObjectsFromArray:obj];
            [self.waitTakeOrderTableView reloadData];
            
            if (obj.count < 10) {
                [self.waitTakeOrderTableView.mj_footer endRefreshingWithNoMoreData];
            }
        }
            break;
        case PTLifeService_TakeOrderUnDoneStatus:
        {
            if (self.currentPageNum ==1) {
                [self.alreadyTakeOrderArray removeAllObjects];
                [self.alreadyTakeOrderTableView.mj_header endRefreshing];
                [self.alreadyTakeOrderTableView.mj_footer resetNoMoreData];
            }
            else
            {
                [self.alreadyTakeOrderTableView.mj_footer endRefreshing];
            }
            [self.alreadyTakeOrderArray addObjectsFromArray:obj];
            [self.alreadyTakeOrderTableView reloadData];
            
            if (obj.count < 10) {
                [self.alreadyTakeOrderTableView.mj_footer endRefreshingWithNoMoreData];
            }
        }
            break;
        case PTLifeService_TakeOrderDoneStatus:
        {
            if (self.currentPageNum ==1) {
                [self.waitDoneArray removeAllObjects];
                [self.waitDoneTableView.mj_header endRefreshing];
                [self.waitDoneTableView.mj_footer resetNoMoreData];
            }
            else
            {
                [self.waitDoneTableView.mj_footer endRefreshing];
            }
            [self.waitDoneArray addObjectsFromArray:obj];
            [self.waitDoneTableView reloadData];
            
            if (obj.count < 10) {
                
                [self.waitDoneTableView.mj_footer endRefreshingWithNoMoreData];
            }
        }
            break;
        case PTLifeService_FinishStatus:
        {
            if (self.currentPageNum ==1) {
                [self.waitCommentArray removeAllObjects];
                [self.waitCommentTableView.mj_header endRefreshing];
                [self.waitCommentTableView.mj_footer resetNoMoreData];
            }
            else
            {
                [self.waitCommentTableView.mj_footer endRefreshing];
            }
            [self.waitCommentArray addObjectsFromArray:obj];
            [self.waitCommentTableView reloadData];
            
            if (obj.count < 10) {
                [self.waitCommentTableView.mj_footer endRefreshingWithNoMoreData];
            }
        }
            break;
    }
}

-(void)createView
{
    UIImageView * backImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0,ScreenWidth, 40)];
    [backImageView setImage:[UIImage imageNamed:@"nav_bar_bg"]];
    backImageView.userInteractionEnabled = YES;
    [self.view addSubview:backImageView];
    
    [backImageView addSubview:self.headerView];
    
    _myReleaseJobScrolView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 40, ScreenWidth, ScreenHeight - TOP_HEIGHT - 40)];
    _myReleaseJobScrolView.pagingEnabled = YES;
    _myReleaseJobScrolView.contentSize = CGSizeMake(ScreenWidth * 5, ScreenHeight - TOP_HEIGHT - 40);
    _myReleaseJobScrolView.showsHorizontalScrollIndicator = NO;
    _myReleaseJobScrolView.delegate = self;
    [self.view addSubview:_myReleaseJobScrolView];
    
    [self.view addSubview:self.myReleaseJobScrolView];
    
    self.allReleaseTableView = [self createTableViewWithPageTag:0];
    [self.myReleaseJobScrolView addSubview:self.allReleaseTableView];
    
    self.waitTakeOrderTableView = [self createTableViewWithPageTag:1];
    [self.myReleaseJobScrolView addSubview:self.waitTakeOrderTableView];
    
    self.alreadyTakeOrderTableView = [self createTableViewWithPageTag:2];
    [self.myReleaseJobScrolView addSubview:self.alreadyTakeOrderTableView];
    
    self.waitDoneTableView = [self createTableViewWithPageTag:3];
    [self.myReleaseJobScrolView addSubview:self.waitDoneTableView];
    
    self.waitCommentTableView = [self createTableViewWithPageTag:4];
    [self.myReleaseJobScrolView addSubview:self.waitCommentTableView];
    
}

-(UITableView *)createTableViewWithPageTag:(NSInteger)pageTag
{
    UITableView * tv = [[UITableView alloc]initWithFrame:CGRectMake(ScreenWidth * pageTag,0, ScreenWidth, ScreenHeight - TOP_HEIGHT - 40) style:UITableViewStylePlain];
    tv.delegate = self;
    tv.dataSource = self;
    tv.backgroundColor = [UIColor clearColor];
    tv.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    WeakSelf;
    tv.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
        if (weakSelf.isRefreshData) {
            
            return ;
        }
        
        //下拉刷新
        weakSelf.currentPageNum = [weakSelf getCurrentRequestPageWithRefresh:YES];
        [weakSelf requestData];
        
    }];
    
    tv.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        
        if (weakSelf.isRefreshData) {
            
            return ;
        }
        //上拉加载
        weakSelf.currentPageNum = [weakSelf getCurrentRequestPageWithRefresh:NO];
        [weakSelf requestData];
    }];
    
    return tv;
}

-(PTStuLifeServiceHeaderView *)headerView
{
    if (_headerView == nil) {
        
        _headerView = [[PTStuLifeServiceHeaderView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth,40) titleArray:[NSArray arrayWithObjects:@"全部",@"待接单",@"已接单",@"待完成",@"待评价", nil]];
        _headerView.delegate = self;
        
        CGFloat buttonW = ScreenWidth/5;
        
        _bottomLabel = [[UILabel alloc]initWithFrame:CGRectMake(((buttonW - 50)/2), 40 - 3 -5,50, 3)];
        _bottomLabel.backgroundColor = [UIColor whiteColor];
        _bottomLabel.layer.cornerRadius = 1.5;
        _bottomLabel.layer.masksToBounds = YES;
        [_headerView addSubview:_bottomLabel];
    }
    return _headerView;
}

#pragma mark - UITableViewDelegate & UITableViewDataSource

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    switch (self.status) {
        case PTLifeService_AllStatus:
            return self.allReleaseArray.count;
            break;
        case PTLifeService_NormalStatus:
            return self.waitTakeOrderArray.count;
            break;
        case PTLifeService_TakeOrderUnDoneStatus:
            return self.alreadyTakeOrderArray.count;
            break;
        case PTLifeService_TakeOrderDoneStatus:
            return self.waitDoneArray.count;
            break;
        case PTLifeService_FinishStatus:
            return self.waitCommentArray.count;
            break;
    }
    return 0;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 194;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * MyReleaseListCellIdentifier = @"MyReleaseListCell";
    
    PTStuLifeServiceMyReleaseCell * myReleaseListCell = [tableView dequeueReusableCellWithIdentifier:MyReleaseListCellIdentifier];
    if (myReleaseListCell == nil) {
        
        myReleaseListCell  = [[PTStuLifeServiceMyReleaseCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyReleaseListCellIdentifier];
        myReleaseListCell.selectionStyle = UITableViewCellSelectionStyleNone;
        myReleaseListCell.delegate = self;
    }
    switch (self.status) {
        case PTLifeService_AllStatus:
            [myReleaseListCell updateServiceMyReleaseCellWith:[self.allReleaseArray objectAtIndex:indexPath.row]];
            break;
        case PTLifeService_NormalStatus:
            [myReleaseListCell updateServiceMyReleaseCellWith:[self.waitTakeOrderArray objectAtIndex:indexPath.row]];
            break;
        case PTLifeService_TakeOrderUnDoneStatus:
            [myReleaseListCell updateServiceMyReleaseCellWith:[self.alreadyTakeOrderArray objectAtIndex:indexPath.row]];
            break;
        case PTLifeService_TakeOrderDoneStatus:
            [myReleaseListCell updateServiceMyReleaseCellWith:[self.waitDoneArray objectAtIndex:indexPath.row]];
            break;
        case PTLifeService_FinishStatus:
            [myReleaseListCell updateServiceMyReleaseCellWith:[self.waitCommentArray objectAtIndex:indexPath.row]];
            break;
    }
    
    return myReleaseListCell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    LifeServiceListModel * listModel = [self getCurrentSelectedModelWithIndex:indexPath.row];
    
    PTStuLSReleaseDetailViewController * releaseDetailViewController = [[PTStuLSReleaseDetailViewController alloc]init];
    releaseDetailViewController.serviceUUID = listModel.serviceUUID;
    [releaseDetailViewController setHidesBottomBarWhenPushed:YES];
    [self.navigationController pushViewController:releaseDetailViewController animated:YES];
}

#pragma mark - MyReleaseCellDelegate Method
//取消订单
-(void)onClickCancelOrderItem:(PTStuLifeServiceMyReleaseCell *)myReleaseCell
{
    self.serviceUUID = myReleaseCell.serviceUUID;
    
    UIAlertView * alertView  =[[UIAlertView alloc]initWithTitle:nil message:@"确定取消此订单?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    alertView.tag = 11;
    [alertView show];
    
}

//删除订单
-(void)onClickDeleteOrderItem:(PTStuLifeServiceMyReleaseCell *)myReleaseCell
{
    self.serviceUUID = myReleaseCell.serviceUUID;
    
    UIAlertView * alertView  =[[UIAlertView alloc]initWithTitle:nil message:@"确定删除此订单？\n（删除后不可恢复）" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    alertView.tag = 22;
    [alertView show];
    
}

//重新发布
-(void)onClickResetReleaseOrderItem:(PTStuLifeServiceMyReleaseCell *)myReleaseCell
{
    NSIndexPath * indexPath = [self getCurrentIndexPathWithCell:myReleaseCell];
    LifeServiceMyListModel * listModel = [self getCurrentSelectedModelWithIndex:indexPath.row];
    
    PTStuLifeServiceReleaseViewController * lifeServiceReleaseViewController = [[PTStuLifeServiceReleaseViewController alloc]init];
    lifeServiceReleaseViewController.isTimeoutOrder = YES;
    lifeServiceReleaseViewController.listModel = listModel;
    [lifeServiceReleaseViewController setHidesBottomBarWhenPushed:YES];
    [self.navigationController pushViewController:lifeServiceReleaseViewController animated:YES];
    
}

//举报
-(void)onClickReportUserItem:(PTStuLifeServiceMyReleaseCell *)myReleaseCell
{
    NSIndexPath * indexPath = [self getCurrentIndexPathWithCell:myReleaseCell];
    LifeServiceMyListModel * listModel = [self getCurrentSelectedModelWithIndex:indexPath.row];
    
    WeakSelf;
    [[PTCoreManager shareInstance]performPostReportUserWithUserName:listModel.userName receiverUUID:listModel.receiver.uuid serviceUUID:listModel.serviceUUID type:[listModel.type integerValue] missionUUID:listModel.missionUUID Completion:^(PTMJsonResult * retObject, NSError * _Nullable retError) {
        
        if (retObject) {
            
            if ([retObject.code integerValue] == kPTCore_Response_Code) {
                
                [weakSelf requestData];
                UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"已举报" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                [alertView show];
            }
        }
        else
        {
            UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"提交错误" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alertView show];
        }
    }];
}

//评价
-(void)onClickCommentsOrderItem:(PTStuLifeServiceMyReleaseCell *)myReleaseCell
{
    NSIndexPath * indexPath = [self getCurrentIndexPathWithCell:myReleaseCell];
    LifeServiceMyListModel * listModel = [self getCurrentSelectedModelWithIndex:indexPath.row];
    
    //显示评价视图
    PTRateView * rateView = [[PTRateView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    rateView.delegate = self;
    [rateView setMyListModel:listModel];
    
    UIWindow * window = [UIApplication sharedApplication].keyWindow;
    [window addSubview:rateView];
    
}

//完成
-(void)onClickFinishOrderItem:(PTStuLifeServiceMyReleaseCell *)myReleaseCell
{
    self.currentReleaseCell = myReleaseCell;
    
    UIAlertView * alertView  =[[UIAlertView alloc]initWithTitle:nil message:@"确定对方已完成该任务？\n（完成后不可撤回）" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    alertView.tag = 33;
    [alertView show];
}

-(NSIndexPath *)getCurrentIndexPathWithCell:(UITableViewCell *)cell
{
    NSIndexPath * indexPath = nil;
    
    switch (self.status) {
        case PTLifeService_AllStatus:
            indexPath = [self.allReleaseTableView indexPathForCell:cell];
            break;
        case PTLifeService_NormalStatus:
            indexPath = [self.waitTakeOrderTableView indexPathForCell:cell];
            break;
        case PTLifeService_TakeOrderUnDoneStatus:
            indexPath = [self.alreadyTakeOrderTableView indexPathForCell:cell];
            break;
        case PTLifeService_TakeOrderDoneStatus:
            indexPath = [self.waitDoneTableView indexPathForCell:cell];
            break;
        case PTLifeService_FinishStatus:
            indexPath = [self.waitCommentTableView indexPathForCell:cell];
            break;
    }
    return indexPath;
}

-(LifeServiceMyListModel *)getCurrentSelectedModelWithIndex:(NSInteger)index
{
    LifeServiceMyListModel * listModel =nil;
    
    switch (self.status) {
        case PTLifeService_AllStatus:
            listModel = [self.allReleaseArray objectAtIndex:index];
            break;
        case PTLifeService_NormalStatus:
            listModel = [self.waitTakeOrderArray objectAtIndex:index];
            break;
        case PTLifeService_TakeOrderUnDoneStatus:
            listModel = [self.alreadyTakeOrderArray objectAtIndex:index];
            break;
        case PTLifeService_TakeOrderDoneStatus:
            listModel = [self.waitDoneArray objectAtIndex:index];
            break;
        case PTLifeService_FinishStatus:
            listModel = [self.waitCommentArray objectAtIndex:index];
            break;
    }
    return listModel;
}

#pragma mark --
#pragma mark --  UIScrollViewDelegate
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    CGFloat pageWidth = self.myReleaseJobScrolView.frame.size.width;
    
    int pageIndex = floor((self.myReleaseJobScrolView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
    
    if (pageIndex==currentPage) {
        
        return;
    }
    
    currentPage = pageIndex;
    
    [self updateUnderlineLocationWithTag:currentPage];
    
    if (currentPage ==0) {
        self.status = PTLifeService_AllStatus;
    }
    else if (currentPage ==1)
    {
        self.status = PTLifeService_NormalStatus;
    }
    else if (currentPage == 2)
    {
        self.status = PTLifeService_TakeOrderUnDoneStatus;
    }
    else if (currentPage ==3)
    {
        self.status = PTLifeService_TakeOrderDoneStatus;
    }
    else if (currentPage == 4)
    {
        self.status = PTLifeService_FinishStatus;
    }
    
    [self requestData];
    
}

-(void)updateUnderlineLocationWithTag:(NSInteger)pageTag
{
    CGFloat buttonW = ScreenWidth/5;
    CGFloat orginx = ((buttonW - 50)/2);
    
    [UIView animateWithDuration:0.5 animations:^{
        
        [self.bottomLabel setFrame:CGRectMake((buttonW * pageTag) + orginx, 40-3-5, 50, 3)];
        
    }];
}

#pragma mark - PTRateViewDelegate  method
-(void)submitRatingInfo:(PTRateView *)rateView
{
    WeakSelf;
    
    [[PTCoreManager shareInstance]performPostPublisherEvaluateWithUserName:rateView.myListModel.userName receiverUUID:rateView.myListModel.receiver.uuid serviceUUID:rateView.myListModel.serviceUUID missionUUID:rateView.myListModel.missionUUID type:[rateView.myListModel.type integerValue] rating:rateView.rating Completion:^(PTMJsonResult *retObject, NSError * _Nullable retError) {
        
        [rateView removeFromSuperview];
        
        if (retObject) {
            
            if ([retObject.code integerValue] == kPTCore_Response_Code) {
                
                [weakSelf requestData];
                UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"已评价" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                [alertView show];
            }
        }
        else
        {
            UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"提交错误" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alertView show];
        }
    }];
}

#pragma mark LifeServiceHeaderViewDelegate Method
-(void)didSelectedHeaderMenuItemIndex:(NSInteger)itemIndex
{
    if (itemIndex==currentPage) {
        
        return;
    }
    
    currentPage = itemIndex;
    
    [self updateUnderlineLocationWithTag:currentPage];
    [self.myReleaseJobScrolView setContentOffset:CGPointMake(ScreenWidth * itemIndex, 0) animated:YES];
    
    if (currentPage ==0) {
        self.status = PTLifeService_AllStatus;
    }
    else if (currentPage ==1)
    {
        self.status = PTLifeService_NormalStatus;
    }
    else if (currentPage == 2)
    {
        self.status = PTLifeService_TakeOrderUnDoneStatus;
    }
    else if (currentPage ==3)
    {
        self.status = PTLifeService_TakeOrderDoneStatus;
    }
    else if (currentPage == 4)
    {
        self.status = PTLifeService_FinishStatus;
    }
    
    [self requestData];
    
}

#pragma mark - UIAlertViewDelegate method
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(alertView.tag == 22 && buttonIndex ==1) {
        
        WeakSelf;
        [[PTCoreManager shareInstance]performPostDeleteMyReleaseOrderWithServiceUUID:self.serviceUUID Completion:^(PTMJsonResult * retObject, NSError * _Nullable retError) {
            
            if (retObject) {
                
                if ([retObject.code integerValue]  == 1000) {
                    
                    [weakSelf requestData];
                    
                    UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"已删除" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                    [alertView show];
                }
            }
            else
            {
                UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"提交错误" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                [alertView show];
                
            }
        }];
    }
    else if (alertView.tag ==11 && buttonIndex ==1)
    {
        WeakSelf;
        [[PTCoreManager shareInstance]performPostCancelMyReleaseOrderWithServiceUUID:self.serviceUUID Completion:^(PTMJsonResult * retObject, NSError * _Nullable retError) {
            
            if (retObject) {
                
                if ([retObject.code integerValue]  == kPTCore_Response_Code) {
                    
                    [weakSelf requestData];
                    
                    UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"已取消" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                    [alertView show];
                
                }
            }
            else
            {
                UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"提交错误" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                [alertView show];
                
            }
            
        }];
    }
    else if (alertView.tag ==33 && buttonIndex ==1)
    {
        NSIndexPath * indexPath = [self getCurrentIndexPathWithCell:self.currentReleaseCell];
        LifeServiceMyListModel * listModel = [self getCurrentSelectedModelWithIndex:indexPath.row];
        
        WeakSelf;
        
        [[PTCoreManager shareInstance]performPostConfirmFinishOrderWithUserName:listModel.userName receiverUUID:listModel.receiver.uuid serviceUUID:listModel.serviceUUID type:[listModel.type integerValue] missionUUID:listModel.missionUUID Completion:^(PTMJsonResult * retObject, NSError * _Nullable retError) {
            
            if (retObject) {
                
                if ([retObject.code integerValue] == kPTCore_Response_Code) {
                    
                    [weakSelf requestData];
                    
                    UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"已完成" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                    [alertView show];
                
                }
            }
            else
            {
                UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"提交错误" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                [alertView show];
            }
            
        }];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
